﻿/*----------------------------------------------------------------------------
文件名：mainFrame.js
创建人：席吉波
创建日期：2012-10-26
用途：用于管理主框架界面布局
----------------------------------------------------------------------------
*/
(function () {
    function execute() {
        mainFrame = function () {

            this.bIsPad = false; // bIsIpad || bIsAndroid;

        }
        mainFrame.prototype = {
            //----------------------------------------------------------------------
            //对于页面布局的初始化
            init: function () {

                var sUserAgent = navigator.userAgent.toLowerCase();
                var bIsAndroid = sUserAgent.match(/android/i) == "android";
                var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";

                this.bIsPad = bIsIpad || bIsAndroid;

                var header = document.getElementById("header");
                var footer = document.getElementById("footer");
                var mainContent = document.getElementById("mainContent");
                var menu = document.getElementById("menu");
                var split = document.getElementById("split");
                var content = document.getElementById("content");

                var height = document.body.clientHeight;
                var width = document.body.clientWidth;

                if (!this.bIsPad) {
                    mainContent.style.height = height - header.clientHeight - footer.clientHeight;
                    $addHandler(window, "resize", Function.createDelegate(this, this.windowAutosize));
                }

                menu.style.height = content.style.height = mainContent.style.height;
                //footer.top = header.clientHeight + mainContent.clientHeight;
                mainContent.style.width = width;
                content.style.width = width - menu.clientWidth ;
                //$get("ifrContent").style.width = content.style.width;
                //$get("ifrContent").style.height = menu.style.height;

            },
            Goto: function (id, title, link) {
                //$tabManage.newTab(id, title, link);
                //window.ifrContent.NewTabPage(id, title, link);
                window.ifrContent.$tabManage.newTab(id, title, link);

            },
            //----------------------------------------------------------------------
            //此函数仅给出一个示例：您可以在javascript中通过如下的方法访问LeftMenu实例
            //并调用其中的方法
            findMenu: function (id) {
                var menu = $find("LeftMenu1");
                menu.menuItemSetCurrentCSS(this, { "id": "menuItem_" + id, "from": "" });

            },
            //----------------------------------------------------------------------
            //此函数用于菜单的显示与隐藏，并调整相关元素的位置、大小
            hide: function (e) {
                var menu = document.getElementById("menu");
                var displayValue = menu.style.display;
                var split = document.getElementById("split");
                var content = document.getElementById("content");

                if (displayValue == "block") {
                    menu.style.display = "none";
                    $common.setVisible($get("LeftMenu1"), false);
                    split.style.left = "0px";
                    content.style.left = "15px";
                    content.style.width = parseInt(content.style.width) + 160;
                    $get("ifrContent").style.width = content.style.width;
                }
                else {
                    menu.style.display = "block";
                    $common.setVisible($get("LeftMenu1"), true);
                    split.style.left = "167px";
                    content.style.left = "182px";
                    content.style.width = parseInt(content.style.width) - 160;
                    $get("ifrContent").style.width = content.style.width;

                    windowAutosize();

                    var leftMenu = $find("LeftMenu1");

                    leftMenu._setSize();
                }
            },

            setMenuLocation: function () {
                var menuDiv = $get("LeftMenu1");
                if (menuDiv != null) {
                    try {
                        
                        var bounds = new Sys.UI.Bounds(4, 0, 167, 20);
                        $common.setLocation(menuDiv, bounds);
                        var clientBounds = $common.getClientBounds();
                        var newBounds = new Object();
                        var topSize = 50;
                        newBounds.width = 167;
                        newBounds.height = clientBounds.height - topSize - 20;

                        $common.setSize(menuDiv, newBounds);

                        // $common.setLocation($get("btnFind"),bounds);

                    }
                    catch (e) {
                        alert(e);
                    }
                }
                if (window.ifrContent.$tabManage) {
                    window.ifrContent.$tabManage.holderResize(Math.max(mainContent.style.height, 50));
                }
                //alert("processed");
            },
            windowAutosize: function () {
                var windowWidth = document.body.offsetWidth;
                var windowHeight = document.body.offsetHeight;

                var containerDiv = $get("container");
                var headerDiv = $get("header");
                var menuDiv = $get("LeftMenu1");
                var splitDiv = $get("split");
                var contentDiv = $get("content");
                var footerDiv = $get("footer");
                var ContentIFrame = $get("ifrContent");
                var menuVisible = $common.getVisible($get("LeftMenu1"));

                containerDiv.style.width = windowWidth;
                containerDiv.style.height = windowHeight;
                if (menuVisible) {
                    menuDiv.style.height = Math.max(windowHeight - headerDiv.offsetHeight , 50);
                }
                contentDiv.style.height = Math.max(windowHeight - headerDiv.offsetHeight , 50);
                splitDiv.style.height = Math.max(windowHeight - headerDiv.offsetHeight , 50);
                //footerDiv.style.top = contentDiv.offsetHeight + headerDiv.offsetHeight;
                contentDiv.style.width = windowWidth - menuDiv.offsetWidth ;
                ContentIFrame.style.width = contentDiv.style.width;
                //window.ifrContent.$tabManage.holderResize(Math.max(windowHeight - headerDiv.offsetHeight - footerDiv.offsetHeight, 50));
            }
        }
        $mainFrame = new mainFrame();

    } //end exec
    if (!window.$mainFrame) {
        execute();
    }
})();
var $mainFrame;